package encryption;

import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.security.MessageDigest;

public class MD5Util {
	public final static String MD5(String s) {
		MessageDigest m = null;
		String hashtext = "";
		try {
			m = MessageDigest.getInstance("MD5");
			m.reset();
			m.update(s.getBytes("UTF-8"));
			byte[] digest = m.digest();
			BigInteger bigInt = new BigInteger(1, digest);
			hashtext = bigInt.toString(16);
			// Now we need to zero pad it if you actually want the full 32
			// chars.
			while (hashtext.length() < 32) {
				hashtext = "0" + hashtext;
			}

		} catch (Exception e) {
			return null;
		} finally {
			m = null;
		}
		return hashtext;

	}

	public static void main(String[] args) throws UnsupportedEncodingException {
		System.out.println(MD5Util
				.MD5("drive_date=20140102&rst_name=常州总站&dst_name=南京"));
		// System.out.println(MD5Util.MD5("加密"));
	}
}
